<template>
	<view class="home_tab">
		<view class="home_tab_title">

			<view class="title_inner">
				<uni-segmented-control
				:current="current"
				:values="items.map((v) => v.title)"
				@clickItem="onClickItem"
				style-type="text"
				active-color="#3bc0bc"
				></uni-segmented-control>
			</view>
			<view class="iconfont icon-iconsearch" @click="search"></view>
		</view>
		<view class="home_tab_content">
			<view v-if="current === 0">
				<home-recommend></home-recommend>
			</view>
			<view v-if="current === 1">
				<home-category></home-category>
			</view>
			
    	</view>
	</view>
</template>
 
<script>
import searchInput from "@/components/searchInput"
import homeCategory from "./home-category"
import homeRecommend from "./home-recommend"
import {uniSegmentedControl} from '@dcloudio/uni-ui'
	export default {
		components:{
      		searchInput,
			homeCategory,
			homeRecommend,
			uniSegmentedControl
		},
		data(){
			return {
				items: [
					{ title: '推荐' },
					{ title: '分类' }
				],
      		current: 0,
    	};
		},
		onShareAppMessage(res) {
		if (res.from === 'button') {// 来自页面内分享按钮
			console.log(res.target)
		}
		return {
			title: '该买就买！拾好货就上Easy商城',
			path: '/pages/home/index'
		}
		},
		onShareTimeline(res) {//分享至朋友圈
		return {
				title: '',
				type: 0,
				query: 0,
				summary: "",
				imageUrl: "",
			}
		},
		methods: {
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex;
				}
			},
			search(){
						uni.navigateTo({
							url:"/pages/search/index"
						})
					}
				},

	}
</script>
	
<style lang="scss">
.home_tab {
  .home_tab_title {
    position: relative;  
    .title_inner {
      width: 30%;
      margin: 0 auto;
    }

      .icon-iconsearch {
            padding: 10rpx;
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            right: 5%;
            font-size: 38rpx;
        }
   
  }
  .home_tab_content {
  }
}
</style>